1 #include<iostream>
2 #include<fstream>
3 #include<sstream>
4 #include<string>
5 #include<stdlib.h>
6 #include<iomanip>
7 #include<math.h>
8 using namespace std;
9 string checkdepart(int z){
10 switch (z){
11 case 1:
12 return "Neurology";
13 break;
14 case 2:
15 return "Pediatrics";
16 break;
17 case 3:
18 return "Emergency";
19 break;
20 case 4:
21 return "Phychiatric";
22 break;
23 case 5:
24 return "E.N.T";
25 break;
26
27 default:
28 return "Internal Medicine";
29
30 }
31 }
32 showneuro(){
33
34 cout<<"\n";
35 //string line;
36 ifstream a;
37
38 a.open("doctors.txt");
39 if(!a)
40 {
41 cout<<"no such file exist"<<endl;
42 return 1;
43 }
44
45 string depart;
46 int x,y,z,b,i=0;
47 cout << setw(5) << "ID:" << setw(15) << "DEPARTMENT" << setw(15) << "NAME" << setw(15) <<"TIMINGS"<<endl << endl;
48
49
50 while (i!=4 )
51 {
52
53 a>>x;
54
55 a.ignore();
56
57 a>>y;
58 depart=checkdepart(y);
59
60 a.ignore();
61
62 a >> z;
63
64 a.ignore();
65
66 a>>b;
67
68 a.ignore();
69 string line;
70 getline(a,line,',');
71
72 cout<<setw(4)<<x<<setw(15)<<depart<<setw(20)<<line<<setw(7)<<z<<"-"<<b<<endl;
73 i++;
74
75 }
76
77
78 a.close();
79
80 }
81 showpediatric(){
82 cout<<"\n";
83 //string line;
84 ifstream a;
85
86 a.open("doctors.txt");
87 if(!a){
88 cout<<"no such file exist"<<endl;
89 return 1;
90 }
91 string discard;
92 getline(a,discard,'$');
93 // cout<<discard;
94 string depart;
95 int x,y,z,b,i=0;
96 cout <<endl<<endl<<endl <<setw(5) << "ID:" << setw(15) << "DEPARTMENT" << setw(15) << "NAME" << setw(15) <<"TIMINGS"<<endl << endl;
97
98
99 while (i!=4 ){
100
101 a>>x;
102
103 a.ignore();
104
105 a>>y;
106 depart=checkdepart(y);
107
108 a.ignore();
109
110 a >> z;
111
112 a.ignore();
113
114 a>>b;
115
116 a.ignore();
117 string line;
118 getline(a,line,',');
119
120 cout<<setw(4)<<x<<setw(15)<<depart<<setw(20)<<line<<setw(7)<<z<<"-"<<b<<endl;
121 i++;
122
123 }
124
125
126 a.close();
127 }
128 showemergency(){
129 cout<<"\n";
130 //string line;
131 ifstream a;
132
133 a.open("doctors.txt");
134 if(!a){
135 cout<<"no such file exist"<<endl;
136 return 1;
137 }
138 string discard;
139 getline(a,discard,'&');
140 // cout<<discard;
141 string depart;
142 int x,y,z,b,i=0;
143 cout <<endl<<endl<<endl << setw(5) << "ID:" << setw(15) << "DEPARTMENT" << setw(15) << "NAME" << setw(15) <<"TIMINGS"<<endl << endl;
144
145
146 while (i!=4 ){
147
148 a>>x;
149
150 a.ignore();
151
152 a>>y;
153 depart=checkdepart(y);
154
155 a.ignore();
156
157 a >> z;
158
159 a.ignore();
160
161 a>>b;
162
163 a.ignore();
164 string line;
165 getline(a,line,',');
166
167 cout<<setw(4)<<x<<setw(15)<<depart<<setw(20)<<line<<setw(7)<<z<<"-"<<b<<endl;
168 i++;
169
170 }
171
172
173 a.close();
174 }
175 showphychiatric(){
176 cout<<"\n";
177 //string line;
178 ifstream a;
179
180 a.open("doctors.txt");
181 if(!a){
182 cout<<"no such file exist"<<endl;
183 return 1;
184 }
185 string discard;
186 getline(a,discard,'@');
187 // cout<<discard;
188 string depart;
189 int x,y,z,b,i=0;
190 cout <<endl<<endl<<endl <<setw(5) << "ID:" << setw(15) << "DEPARTMENT" << setw(15) << "NAME" << setw(15) <<"TIMINGS"<<endl << endl;
191
192 while (i!=4 ){
193
194 a>>x;
195
196 a.ignore();
197
198 a>>y;
199 depart=checkdepart(y);
200
201 a.ignore();
202
203 a >> z;
204
205 a.ignore();
206
207 a>>b;
208
209 a.ignore();
210 string line;
211 getline(a,line,',');
212
213 cout<<setw(4)<<x<<setw(17)<<depart<<setw(20)<<line<<setw(7)<<z<<"-"<<b<<endl;
214 i++;
215
216 }
217
218
219 a.close();
220 }
221 showent(){
222 cout<<"\n";
223 //string line;
224 //brought to you by code-projects.org
225 ifstream a;
226
227 a.open("doctors.txt");
228 if(!a){
229 cout<<"no such file exist"<<endl;
230 return 1;
231 }
232 string discard;
233 getline(a,discard,'#');
234 // cout<<discard;
235 string depart;
236 int x,y,z,b,i=0;
237 cout <<endl<<endl<<endl <<setw(5) << "ID:" << setw(15) << "DEPARTMENT" << setw(15) << "NAME" << setw(15) <<"TIMINGS"<<endl << endl;
238
239 while (i!=4 ){
240
241 a>>x;
242
243 a.ignore();
244
245 a>>y;
246 depart=checkdepart(y);
247
248 a.ignore();
249
250 a >> z;
251
252 a.ignore();
253
254 a>>b;
255
256 a.ignore();
257 string line;
258 getline(a,line,',');
259
260 cout<<setw(4)<<x<<setw(15)<<depart<<setw(20)<<line<<setw(7)<<z<<"-"<<b<<endl;
261 i++;
262
263 }
264
265
266 a.close();
267 }
268 showinternalmed(){
269 cout<<"\n";
270 //string line;
271 ifstream a;
272
273 a.open("doctors.txt");
274 if(!a){
275 cout<<"no such file exist"<<endl;
276 return 1;
277 }
278 string discard;
279 getline(a,discard,'%');
280 // cout<<discard;
281 string depart;
282 int x,y,z,b,i=0;
283 cout <<endl<<endl<<endl <<setw(5) << "ID:" << setw(15) << "DEPARTMENT" << setw(18) << "NAME" << setw(15) <<"TIMINGS"<<endl << endl;
284
285 while (i!=4 ){
286
287 a>>x;
288
289 a.ignore();
290
291 a>>y;
292 depart=checkdepart(y);
293
294 a.ignore();
295
296 a >> z;
297
298 a.ignore();
299
300 a>>b;
301
302 a.ignore();
303 string line;
304 getline(a,line,',');
305
306 cout<<setw(4)<<x<<setw(20)<<depart<<setw(18)<<line<<setw(7)<<z<<"-"<<b<<endl;
307 i++;
308
309 }
310
311
312 a.close();
313 }
314 bool checkavailibility(int id){
315 fstream a ("appointment.txt");
316 if (!a)
317 {
318
319 cout << "Can't open file" << endl;
320 return 1;
321 }
322
323 int number;
324
325 a >> number;
326
327 while(!a.eof())
328 {
329 if (number == id)
330 {
331 return false;
332 }
333 a >> number;
334
335 }
336 return true;
337 a.close();
338 }
339 makeappointment(int d){
340 bool check=false;
341 while(!check){
342
343
344 int id;
345 cout<<"Enter your desired doctor's ID number:"<<endl;
346 cin>>id;
347 while(cin.fail())
348 {
349 cout<<"enter an integer from above choices"<<endl;
350 cin.clear();
351 cin.ignore(256,'\n');
352
353 cin >> id;
354 }
355 switch(d){
356 case 1:
357 do {
358
359 if(id<=0 || id>4){
360 cout<<"enter valid doctor's id number (as shown above)"<<endl;
361 }
362 else
363 break;
364 cout<<"Enter your desired doctor's id number:";
365 cin>>id;
366 } while (id<=0 || id>4);
367 break;
368 case 2:
369 do {
370
371 if(id<=4 || id>8){
372 cout<<"enter valid doctor's id number (as shown above)"<<endl;
373 }
374 else
375 break;
376
377 cout<<"Enter your desired doctor's id number:";
378 cin>>id;
379 } while (id<=4 || id>8);
380 break;
381 case 3:
382 do {
383
384 if(id<=20 || id>24){
385 cout<<"enter valid doctor's id number (as shown above)"<<endl;
386 }
387 else
388 break;
389 cout<<"Enter your desired doctor's id number:";
390 cin>>id;
391 } while (id<=20 || id>24);
392 break;
393 case 4:
394 do {
395
396 if(id<=12 || id>16){
397 cout<<"enter valid doctor's id number (as shown above)"<<endl;
398 }
399 else
400 break;
401 cout<<"Enter your desired doctor's id number:";
402 cin>>id;
403 } while (id<=12 || id>16);
404 break;
405 case 5:
406 do {
407
408 if(id<=16 || id>20){
409 cout<<"enter valid doctor's id number (as shown above)"<<endl;
410 }
411 else
412 break;
413 cout<<"Enter your desired doctor's id number:";
414 cin>>id;
415 } while (id<=16 || id>20);
416 break;
417 case 6:
418 do {
419
420 if(id<=8 || id>12){
421 cout<<"enter valid doctor's id number (as shown above)"<<endl;
422 }
423 else
424 break;
425 cout<<"Enter your desired doctor's id number:";
426 cin>>id;
427 } while (id<=8 || id>12);
428 break;
429 default:
430 cout<<"enter valid input"<<endl;
431 }
432
433 bool found=checkavailibility(id);
434
435 if(!found){
436 cout<<"doctor unavailable"<<endl;
437
438 }
439 else{
440
441 string data;
442
443 ofstream a;
444 a.open ("appointment.txt", std::ofstream::out | std::ofstream::app);
445
446
447
448 a<<id<<endl;
449 check=true;
450 cout<<"\nAppointment successfully done....";
451 }
452 int set();
453
454 }
455
456 }
457 checkappointment(int id){
458
459 ifstream a ("appointment.txt");
460 if (!a)
461 {
462
463 cout << "Can't open file" << endl;
464 return 1;
465 }
466
467 int number;
468 bool found;
469 a >> number;
470
471
472 while(!a.eof())
473 {
474 if (number == id)
475 {
476 cout << "found\nplease proceed to the waiting area on your left\nyou'll shortly be guided to your Doctor" << endl;
477 found=true;
478
479 }
480 a >> number;
481
482 }
483 if(!found){
484 cout<<"not found\n";
485
486 }
487 a.close();
488 }
489
490
491
492 class Person
493 {
494 protected:
495 int id;
496 string name;
497 char gender;
498 long long phone_num;
499
500 public:
501 void set()
502 {
503 cin.ignore();
504 cout<<"\n\n\t\t--------------------\n";
505 cout<<"\t\tEnter Name:";
506 getline(cin,name);
507
508 cout<<"\n\t\tEnter Gender(M/F):";
509
510 cin>>gender;
511 bool check=false;
512
513 while(check==false){
514
515
516 if(gender!='M'&&gender!='m'&&gender!='F'&&gender!='f')
517 {
518
519
520 try
521 {
522 throw &gender;
523 }
524 catch (char *gender)
525 {
526 cout<<"enter valid input:"<<endl;
527 cin>>*gender;
528 if(*gender=='M'||*gender=='m'||*gender=='F'||*gender=='f'){
529 check=true;
530 }
531 }
532 }
533 else{
534 check=true;
535 }
536 }
537 cout<<"\n\t\tEnter phone number:";
538 cin.ignore();
539 cin>>phone_num;
540 while(cin.fail()) {
541 cout<<"Phone number is in integer form,sire!";
542 cin.clear();
543 cin.ignore(256,'\n');
544
545 cin >> phone_num;
546 }
547
548
549 }
550
551 string getname()
552 {
553 return name;
554 }
555 int getid()
556 {
557 return id;
558 }
559 char getgender()
560 {
561 return gender;
562
563 }
564
565 long getphone()
566 {
567 return phone_num;
568 }
569 };
570 class Doctor:public Person
571 {
572 private:
573 string specialization;
574 public:
575 setspcialization(string sp){
576 specialization=sp;
577 }
578 string getspecialization(){
579 return specialization;
580 }
581 void checkPatient(){
582 cout<<"Patient checked.";
583 }
584 void prescribeMedicine(){
585 cout<<"Medicine prescription sent to pharmacy."<<endl;
586 }
587 void generateReport(){
588 cout<<"reports will be available to collect after 10 days from the check-up date."<<endl;
589 }
590 };
591 class Patient:public Person
592 {
593 int choice;
594 public:
595 int set()
596 {
597
598 Person::set();
599 system("CLS");
600 cout<<"\n\t\t\t\tChoose Department:"<<endl;
601 cout<<"\n\t\t\t\t1)Neurology \n\t\t\t\t2)Pediatric \n\t\t\t\t3)Internal Medicine \n\t\t\t\t4)Phychiatric \n\t\t\t\t5)E.N.T \n\t\t\t\t6)Emergency \n\n\n\t\t\tYour Choice:";
602 cin>>choice;
603 while(cin.fail()) {
604 cout<<"enter an integer from above choices";
605 cin.clear();
606 cin.ignore(256,'\n');
607
608 cin >> choice;
609 }
610 bool check=false;
611
612 while(!check){
613 if(choice>=1&&choice<=6){
614 check=true;
615 }
616 else{
617 try
618 {
619 throw &choice;
620 }
621 catch(int *choice)
622 {
623 cout<<"enter valid input:"<<endl;
624 cin>>*choice;
625 while(cin.fail()) {
626 cout<<"enter an integer from above choices";
627 cin.clear();
628 cin.ignore(256,'\n');
629
630 cin >> *choice;
631 }
632 }
633 }
634 }
635 switch(choice)
636 {
637 case 1:
638
639 showneuro();
640 break;
641 case 2:
642
643 showpediatric();
644 break;
645 case 3:
646
647 showinternalmed();
648 break;
649 case 4:
650
651 showphychiatric();
652 break;
653
654 case 5:
655 showent();
656 break;
657
658 case 6:
659 showemergency();
660 break;
661
662 default:
663 cout<<"\nDepartment not present:\n";
664 }
665 return choice;
666 }
667 };
668 class Receptionist:public Person
669 {
670 bool available=false;
671 char ans;
672 int id=90;
673 public:
674 Receptionist(){
675
676 }
677 Receptionist(int d){
678 cout<<"Do you have an appointment(Y/N)?"<<endl;
679 cin>>ans;
680 bool check=false;
681 //acception handling
682 while(check==false){
683
684
685 if(ans!='Y'&&ans!='y'&&ans!='N'&&ans!='n')
686 {
687
688
689 try
690 {
691 throw &ans;
692 }
693 catch (char *ans)
694 {
695 cout<<"enter valid input:"<<endl;
696 cin>>*ans;
697 if(*ans=='Y'||*ans=='y'||*ans=='N'||*ans=='n'){
698 check=true;
699 }
700 }
701 }
702 else{
703 check=true;
704 }
705 }
706 char choice;
707 switch(ans)
708 {
709
710 case 'n':
711 case 'N':
712
713 cout<<"do you want to make an appointment?(M) OR Walk in?(W)";
714
715 cin>>choice;
716 check=false;
717 //acception handling
718 while(check==false){
719
720
721 if(choice!='M'&&choice!='m'&&choice!='W'&&choice!='w')
722 {
723
724
725 try
726 {
727 throw &choice;
728 }
729 catch (char *choice)
730 {
731 cout<<"enter valid input:"<<endl;
732 cin>>*choice;
733 if(*choice=='M'||*choice=='m'||*choice=='W'||*choice=='w'){
734 check=true;
735 }
736 }
737 }
738 else{
739 check=true;
740 }
741 }
742 if(choice=='M'||choice=='m'){
743 makeappointment(d);
744 }
745 else if(choice=='W'||choice=='w'){
746 while(!available){
747
748 switch(d){
749 case 1:
750 do {
751 cout<<"Enter your desired doctor's id number:";
752 cin>>id;
753 while(cin.fail())
754 {
755 cout<<"cenrtainly you made a typo!"<<endl;
756 cin.clear();
757 cin.ignore(256,'\n');
758
759 cin >> id;
760 }
761 if(id<=0 || id>4){
762 cout<<"enter valid doctor's id number (as shown above)"<<endl;
763 }
764 } while (id<=0 || id>4);
765 break;
766 case 2:
767 do {
768 cout<<"Enter your desired doctor's id number:";
769 cin>>id;
770 while(cin.fail())
771 {
772 cout<<"certainly you made a typo!"<<endl;
773 cin.clear();
774 cin.ignore(256,'\n');
775
776 cin >> id;
777 }
778 if(id<=4 || id>8){
779 cout<<"enter valid doctor's id number (as shown above)"<<endl;
780 }
781 } while (id<=4 || id>8);
782 break;
783 case 3:
784 do {
785 cout<<"Enter your desired doctor's id number:";
786 cin>>id;
787 while(cin.fail())
788 {
789 cout<<"certainly you made a typo!"<<endl;
790 cin.clear();
791 cin.ignore(256,'\n');
792
793 cin >> id;
794 }
795 if(id<=20 || id>24){
796 cout<<"enter valid doctor's id number (as shown above)"<<endl;
797 }
798 } while (id<=20 || id>24);
799 break;
800 case 4:
801 do {
802 cout<<"Enter your desired doctor's id number:";
803 cin>>id;
804 while(cin.fail())
805 {
806 cout<<"cenrtainly you made a typo!"<<endl;
807 cin.clear();
808 cin.ignore(256,'\n');
809
810 cin >> id;
811 }
812 if(id<=12 || id>16){
813 cout<<"enter valid doctor's id number (as shown above)"<<endl;
814 }
815 } while (id<=12 || id>16);
816 break;
817 case 5:
818 do
819 {
820 cout<<"Enter your desired doctor's id number:";
821 cin>>id;
822 while(cin.fail())
823 {
824 cout<<"certainly you made a typo!"<<endl;
825 cin.clear();
826 cin.ignore(256,'\n');
827
828 cin >> id;
829 }
830 if(id<=16 || id>20){
831 cout<<"enter valid doctor's id number (as shown above)"<<endl;
832 }
833 } while (id<=16 || id>20);
834 break;
835 case 6:
836 do {
837 cout<<"Enter your desired doctor's id number:";
838 cin>>id;
839 while(cin.fail())
840 {
841 cout<<"cenrtainly you made a typo!"<<endl;
842 cin.clear();
843 cin.ignore(256,'\n');
844
845 cin >> id;
846 }
847 if(id<=8 || id>12){
848 cout<<"enter valid doctor's id number (as shown above)"<<endl;
849 }
850 } while (id<=8 || id>12);
851 break;
852 default:
853 cout<<"enter valid input"<<endl;
854 }
855
856 available=checkavailibility(id);
857 if (!available){
858 cout<<"not available at this time"<<endl;
859 }
860 else {
861 cout<<"doctor available"<<endl;
862 }
863 }
864
865 }
866 else
867 cout<<"enter valid input";
868
869 break;
870
871 case 'y':
872 case 'Y':
873
874 int id;
875
876 cout<<"enter your assigned doctor's ID number:";
877 cin>>id;
878 while(cin.fail()) {
879 cout<<"certainly you made a typo!"<<endl;
880 cin.clear();
881 cin.ignore(256,'\n');
882 cin >> id;
883 }
884 checkappointment(id);
885 break;
886 default:
887 cout<<"";
888 }
889 }
890 };
891 class Building
892 {
893 private:
894 int No_of_Rooms;
895 public:
896
897
898 updatedoctor(){
899 fstream fin;
900 fin.open("doctors.txt",fstream::in);
901
902 stringstream sstr;
903
904 string x;
905 string o;
906 string temp;
907 cin.ignore();
908 cout<<"Enter the name of Doctor which you want to replace:"<<endl;
909
910 getline(cin,x);
911
912 cout<<"Enter the name of new doctor:";
913 getline(cin,o);
914
915
916 int comma=0;
917 while(! fin.eof() ) {
918 getline(fin, temp, '\n');
919 if (temp.find(x) != std::string::npos) {
920 for (int i=0; i<temp.length(); i++) {
921 sstr<<temp[i];
922 if (temp[i] == ',') {
923 comma++;
924 }
925 if (comma==4) {
926 break;
927 }
928 }
929 sstr<<o<<",";
930 if (temp[temp.length()-1] != ',') {
931 sstr<<temp[temp.length()-1];
932 }
933 sstr<<endl;
934 //cout<<o<<","<<endl;
935
936 } else {
937 sstr << temp << endl;
938 //cout<<temp<<endl;
939 }
940 }
941
942 fin.close();
943
944 fstream fout;
945 fin.open("doctors.txt", fstream::out | fstream::trunc);
946 fin << sstr.str();
947 //cout<< sstr.str();
948 }
949
950
951 bool checkpass(string pass){
952 string password="pass";//operator overloadig cAN BE DONE.
953 if(password==pass){
954 return true;
955 }
956 else
957 return false;
958 }
959 };
960
961 int main(void){
962 cout<<setw(30)<<"\t\t\t-------------------";
963 cout<<setw(30)<<"\n\t\t\t\tHOSPITAL MANAGEMENT"<<endl;
964 cout<<setw(30)<<"\t\t\t-------------------"<<endl;
965 int ans;
966 bool check=false;
967 cout<<"\t\tPRESS 1 : To View Doctors Present in our hospital"<<endl;
968 cout<<"\n\t\tPRESS 2 : To Go To Appointment Section"<<endl;
969 cout<<"\t\t-----------------------------";
970 cout<<"\n\t\tAdministration Login"<<endl;
971 cout<<"\t\tPRESS 3 : To Update Doctor";
972 cout<<"\n\t\t-----------------------------";
973 cout<<"\n\n\t\t\t\tInput:";
974 cin>>ans;
975 while(cin.fail()) {
976 cout<<"enter an integer from above choices"<<endl;
977 cin.clear();
978 cin.ignore(256,'\n');
979
980 cin >> ans;
981 }
982 while(!check){
983 if(ans>=1&&ans<=3){
984 check=true;
985 }
986 else{
987 try
988 {
989 throw &ans;
990 }
991 catch(int *ans)
992 {
993 cout<<"enter valid input:"<<endl;
994 cin>>*ans;
995 while(cin.fail()) {
996 cout<<"enter an integer from above choices"<<endl;
997 cin.clear();
998 cin.ignore(256,'\n');
999
1000 cin >> *ans;
1001 }
1002 }
1003
1004 }
1005 }
1006 int pass,d;
1007
1008 switch (ans){
1009 case 1:
1010 system("CLS");
1011 showneuro();
1012 showpediatric();
1013 showemergency();
1014 showphychiatric();
1015 showent();
1016 showinternalmed();
1017
1018 break;
1019
1020 case 2:
1021 {
1022 Patient pa;
1023 d=pa.set();
1024 }
1025 {
1026 Receptionist re(d);
1027 }
1028 break;
1029 case 3:
1030 {
1031 Building b;
1032 string pass;
1033 bool check=false;
1034 while(check!=true){
1035
1036 cout<<"\n\t\t\t\tEnter pass key:";
1037 cin>>pass;
1038 check=b.checkpass(pass);
1039 if(check==true){
1040 cout<<"\n\n\t\t\t\tAccess granted"<<endl;
1041 b.updatedoctor();
1042 }
1043
1044 else
1045 cout<<"\n\n\t\t\t\tAccess denied"<<endl;
1046 }}
1047 break;
1048 default:
1049 cout<<"enter valid input"<<endl;
1050
1051 }
1052 system("pause");
1053 }